package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("stu")
public class StudentController {

    @Reference
    private StudentService studentService;

    //添加
    @PostMapping
    //@RequestBody 主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的);
    //当前对象获取整个http请求的body里面的所有数据
    //注:一个请求，只有一个RequestBody;一个请求，可以有多个RequestParam
    public int addStudent(@RequestBody Student student){
        int add = studentService.add(student);
        return add;
    }

    //更新
    @PutMapping
    public int updateStudent(@RequestBody Student student){
        int update = studentService.update(student);
        return update;
    }

    //删除
    @DeleteMapping("{id}")
    public int deleteStudent(@PathVariable Integer id){
        int delete = studentService.delete(id);
        return delete;
    }

    //查单个
    @GetMapping("{id}")
    public Student findByIdStudent(@PathVariable Integer id){
        Student byId = studentService.findById(id);
        return byId;
    }

    //查全部
    @GetMapping
    public List<Student> findAll(){
        return studentService.findAll();
    }
}
